import { nextTick } from 'vue'
import { useFormItem } from 'element-plus'

//  触发所在 el-form-item的校验事件 trigger，常用于自定义表单组件上
export function useTrigger() {
	const { formItem } = useFormItem() // form formItem
	// const emitTrigger = (value: any) => {
	const emitTrigger = () => {
		if (formItem) {
			nextTick(() => {
				formItem.validate('blur') // 触发校验
				formItem.validate('change') // 触发校验
			})
		}
	}
	return { formItem, emitTrigger }
}
